public class Main {


    public static void main(String[] args) {

        Person [] people=new Person[3];
        people[0]=new Student();
        people[0].name="小明";
        people[1]=new Student();
        people[1].name="小红";

        people[2]=new Teacher();
        people[2].name="老师";

        for (int i = 0; i < 3; i++) {

            people[i].eat();
            people[i].sleep();

            if(people[i].getClass() == Student.class)
            {
                // 向下转型
                Student s = (Student)people[i];
                //
                s.dohomework();
            }

            else if(people[i] instanceof Teacher)
            {
                Teacher t = (Teacher)people[i];
                t.checkhomework();
            }
        }

    }
}